package cn.wp.ewallet.common.dao.impl;

import cn.wp.common.core.dao.SqlString;
import cn.wp.ewallet.common.dao.MoneyTypeInfoDao;
import cn.wp.ewallet.common.model.entity.MoneyTypeInfoDoo;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;
import cn.wp.common.core.dao.JdbcSupportTemplate;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;

/**
 * 币种信息-数据访问层实现
 * Created by zhangyongli on 2020/01/13
 */
@Repository
public class MoneyTypeInfoDaoImpl implements MoneyTypeInfoDao {

    @Autowired
    private JdbcSupportTemplate jdbcSupportTemplate;

    @Override
    public List<MoneyTypeInfoDoo> selectMoneyTypeInfo(String moneyTypeCode) {

        SqlString sqlString = SqlString.newInstance();
        sqlString.add("select m.*, d.contract_address, d.web_url, d.money_white_book, d.money_issu_date");
        sqlString.add("    , d.money_comm");
        sqlString.add("from money_type_info m");
        sqlString.add("    left join digital_money_info d on m.money_type_id = d.money_type_id");

        List<String> params = new ArrayList<>();
        if (StringUtils.isNotEmpty(moneyTypeCode)) {
            sqlString.add("where m.money_type_id = ?");
            params.add(moneyTypeCode);
        }
        return jdbcSupportTemplate.selectList(sqlString.build(), params.toArray(), MoneyTypeInfoDoo.class);
    }
}